﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BPO;
namespace PlotBookingRegistration
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            ProcessLogin();
        }

        private void ProcessLogin()
        {
            Security.getInstance().ValidateUser(txtUserName.Text, txtPassword.Text,cboRole.SelectedValue.ToString());
            if (Security.getInstance().IsUserLoggedIn)
            {
                new HOME().Show();
                this.Hide();
            }
            else
                MessageBox.Show("Invalid Credentials");
        }

        private void Login_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter || e.KeyChar==(char)Keys.Return)
            {
                ProcessLogin();
            }
            else if (e.KeyChar == (char)Keys.Escape)
            {
                this.Close();
            }
            
        }

        private void Login_Load(object sender, EventArgs e)
        {
            try
            {
                LoadRoleCombo();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void LoadRoleCombo()
        {
            BPO.Utility.BindDropDown(cboRole, "Designation", "A");
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
